import SDKManager from "../SDKManager";
import { BattleID } from "../SDKConfig";
import { EventName } from "../../public/Config";
import GlobalEvent from "../../cfw/event/GlobalEvent";

const { ccclass, property } = cc._decorator;

@ccclass
export default class MoreGameComp extends cc.Component {


    @property
    from: number = 0;

    start() {
        this.node.active = false;
        GlobalEvent.instance().on(EventName.ZS_DATA, this.updateContent, this)

    }

    updateContent() {
        if (!cc.isValid(this.node)) {
            return;
        }
        let flag2 = SDKManager.getChannel().isSwtichOpen();
        let flag = SDKManager.getChannel().hasMoreGame() && flag2
        // this.node.active = flag;
        if (flag) {
            this.node.active = false;
            //tt
            SDKManager.getChannel().createMoreGameButton()
        } else {
            // qq 
            let flag = SDKManager.getChannel().hasAppBox()
            this.node.active = flag;

        }

    }

    // update (dt) {}

    onDestroy() {
        SDKManager.getChannel().hideMoreGameButton()
        GlobalEvent.instance().off(EventName.ZS_DATA, this.updateContent, this)
        // SDKManager.getChannel().destroyAppBoxAd()
    }

    onButtonClick() {
        // SDKManager.getChannel().showMoreGameView()
        // console.log("MoreGameComp onButtonClick ")
        if (this.from == 0) {
            SDKManager.getChannel().battleStart(BattleID.ENTER_EXPORT1_FROM_LOGIN)
        } else {
            SDKManager.getChannel().battleStart(BattleID.ENTER_EXPORT1_FROM_LOBBY)

        }
        SDKManager.getChannel().showAppBoxAd(0)

    }
}
